

*-------------------------------------------------------------------------------
* collapse traffic-stop data to agency-month level
*-------------------------------------------------------------------------------

* traffic stop data
use "data/outputs/TSSS_beat.dta", clear

* collapse
replace agencyname = "troopers" if regexm(agencyname, "ILLINOIS")
replace agencyname = "cpd" if regexm(agencyname, "CHICAGO")
replace agencyname = "MSA" if agencyname ~= "troopers" & agencyname ~= "cpd"
collapse (sum) count citation black white black_citation white_citation ///
		reason_*, by(agencyname month)


* reshape
reshape wide count citation black white black_citation white_citation ///
			 reason_*, i(month) j(agencyname, string)

* citation rates
gen citationratecpd = citationcpd / countcpd
gen citationratetroopers = citationtroopers / counttroopers

* proportion of stops for equipment
gen equiprate_cpd = reason_equipcpd / countcpd
gen equiprate_troopers = reason_equiptroopers / counttroopers

* shaded region
gen treatment = 1 if (month >= tm(2015m8) & month <= tm(2016m1))
		


*-------------------------------------------------------------------------------
* graphs
*-------------------------------------------------------------------------------

* citation rate
#delimit;
twoway (area treatment month if month >= tm(2012m1) & month <= tm(2020m2), 
lcolor(gs15%100) fcolor(gs15%100))
(connected citationratetroopers month if month >= tm(2012m1) & month <= tm(2020m3),
lcolor(gs8) mcolor(gs8) msize(small) msymbol(square))
(connected citationratecpd month if month >= tm(2012m1) & month <= tm(2020m3),
lcolor(blue) mcolor(blue) msize(small) msymbol(O)),
graphregion(fcolor(white) lcolor(white) margin(zero))
plotregion(fcolor(white) lstyle(none) lcolor(white) ilstyle(none))
xsize(7) ysize(5)
title("", 
	  color(black) placement(west) justification(left) size(medlarge)) 
ytitle("Proportion of traffic stops producing a citation", size(medlarge))
yscale(lcolor(none))
ylabel(0(.2)1, labsize(large) glcolor(white) angle(horizontal) axis(1))
xtitle("", size(medsmall)) 
xscale(lcolor(none) range(636 722))
xlabel(624(12)720, labsize(medlarge) format(%tmCY)) 
legend(order(3 "Chicago Police" 2 "Illinois State Police")
ring(0) pos(2) rows(2) symxsize(*.25));
graph export "figures/Figure3a.pdf", replace;


* equipment rate
#delimit;
twoway (area treatment month if month >= tm(2012m1) & month <= tm(2020m2), 
lcolor(gs15%100) fcolor(gs15%100))
(connected equiprate_troopers month if month >= tm(2012m1) & month <= tm(2020m3),
lcolor(gs8) mcolor(gs8) msize(small) msymbol(square))
(connected equiprate_cpd month if month >= tm(2012m1) & month <= tm(2020m3),
lcolor(blue) mcolor(blue) msize(small) msymbol(O)),
graphregion(fcolor(white) lcolor(white) margin(zero))
plotregion(fcolor(white) lstyle(none) lcolor(white) ilstyle(none))
xsize(7) ysize(5)
title("", 
	  color(black) placement(west) justification(left) size(medlarge)) 
ytitle("Proportion of traffic stops for equipment", size(medlarge))
yscale(lcolor(none))
ylabel(0(.2)1, labsize(large) glcolor(white) angle(horizontal) axis(1))
xtitle("", size(medsmall)) 
xscale(lcolor(none) range(636 722))
xlabel(624(12)720, labsize(medlarge) format(%tmCY)) 
legend(order(3 "Chicago Police" 2 "Illinois State Police")
ring(0) pos(2) rows(2) symxsize(*.25));
graph export "figures/Figure3b.pdf", replace;

# delimit cr

*-------------------------------------------------------------------------------
* regressions reported in text
*-------------------------------------------------------------------------------

keep month equiprate* citationrate*
reshape long equiprate_ citationrate, i(month) j(agency, string)
gen treat = (month >= tm(2016m1) & agency == "cpd")
reghdfe citationrate treat if month >= tm(2012m1) & month <= tm(2020m2), a(agency month) vce(r)
reghdfe equiprate treat if month >= tm(2012m1) & month <= tm(2020m2), a(agency month) vce(r)



	
* End
